import router from './router'
import { getAuthorization, getAppId } from '@/utils/auth'

const whiteList = ['/login', '/404']

router.beforeEach((to, from, next) => {
  // 有用户信息
  if (getAuthorization() && getAppId()) {
    // if (to.path === "/login") {
    //   next({ path: "/" });
    //   NProgress.done();
    // } else {
    //   next();
    //   NProgress.done();
    // }
    // 不用限制登录页
    next()
  } else {
    // 没有用户信息
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next(`/login?redirect=${to.path}`)
    }
  }
})
